<?php
/**
 * vim: et ts=4 sts=4 sw=4 fdm=marker
 *
 * 基类--错误处理	 
 *
 * @author	wang Penghai <china_php@hotmail.com>
 * @copyright 2008 5e6d Corporation.
 * @version   $Id:$
 */

class pf_log{

	/*{{{ member*/
	/**
	 * 保存信息数组
	 */
	protected $__msg = array();
	/*}}}*/
	/*{{{ function*/
	/*{{{ function setError()*/
	
	/**
	 * 设置错误
	 *
	 * @param array $argvs = array(
	 *				*'cohe' => '10001',//错误代码
	 *				*'msg' => 'error info ',//错误信息，为英文，能表明什么意思就行
	 *		);
	 *
	 *@return void
	 **/
	public function set_error(array $argvs)
	{
		$er_trace = debug_backtrace();
		if (is_array($er_trace)) {
			foreach ($er_trace as $this_key => $this_trace) {
				$this_file = $this_method ='';
				if (isset($this_trace['file'])) {
					$this_file .= $this_trace['file'];
				}
				if (isset($this_trace['line'])) {
					$this_file .= ' on line '.$this_trace['line'];
				}
				if (isset($this_trace['class'])) {
					$this_method .= $this_trace['class'];
				}
				if (isset($this_trace['type'])) {
					$this_method .= $this_trace['type'];
				}
				if (isset($this_trace['function'])) {
					$this_method .= $this_trace['function'].'()';
				}
				$er_trace[$this_key] = array($this_file, $this_method);
			}
		}

		$argvs['er_trace'] = $er_trace;
		$argvs['code'] = isset($argvs['code'])?$argvs['code']:'00000';
		$argvs['msg'] = isset($argvs['msg'])?$argvs['msg']:'sys msg!';
		if (empty($this->__msg)) {
			$this->__msg = $argvs;
		}else {
			$this->__msg[] = $argvs;
		}	
	}

	/*}}}*/
	/*{{{ public function getError()*/

	/**
	 * 获取错误信息
	 *
	 * @retrun $this->__msg 错误信息
	 */
	public function get_error()
	{
		return $this->__msg;
	}

	/*}}}*/
	/*{{{ public function printMsg()*/

	/**
	 * 打印错误信息
	 *
	 * @return void
	 */
	public function print_msg()
	{
		var_export($this->__msg);
	}
	/*}}}*/
	/*}}}*/
}
